package com.cy.pj.common.web;

import com.cy.pj.common.pojo.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice//@ControllerAdvice+@ResponseBody=@RestControllerAdvice
//@ControllerAdvice
//@ResponseBody
//异常处理类
/**
 * 此@RestControllerAdvice注解描述的类为全局异常处理类
 */
public class GlobalExceptionHandler {
    private static  final Logger lg=
            LoggerFactory.getLogger(GlobalExceptionHandler.class);

    /**
     * ExceptionHandler注解描述的方法为异常处理方法
     * 注解中定义的异常类型为方法可以处理的异常类型
     * @param e
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    public JsonResult doHandleRuntimeException(RuntimeException e){
        e.printStackTrace();
        lg.error("sexception msg is {}",e.getMessage());
        return new JsonResult();

    }

}
